package JulMonth;

import static java.lang.Math.sqrt;

public class Fourth {
    public static void main(String[] args) {
//        int[] arr=new int[]{0,0,0,0,0,0,0};
//        duplicateZeros(arr);
        isHappy(2);
    }
    public static boolean isHappy(int n) {
        int slow=n;
        int fast=sum(n);
        while(fast!=slow){
            slow=sum(slow);
            fast=sum(sum(fast));
        }
        return fast==1;
    }
    public static int sum (int num){
        int n=0;
        while(num!=0){
            n+=Math.sqrt(num%10);
            num/=10;
        }
        return n;
    }
    public static void duplicateZeros(int[] arr) {
        if(arr.length==1){
            return;
        }
        if(arr.length==2){
            if(arr[0]==0){
                arr[1]=0;
            }
            return;
        }
        int cur=0;
        int dest=-1;
        while(cur<arr.length){
            if(arr[cur]==0){
                dest+=2;
            }else{
                dest++;
            }
            if(dest>=arr.length-1){
                break;
            }
            cur++;
        }
        if(dest==arr.length){
            arr[dest-1]=0;
            dest-=2;
            cur--;
        }
        while(cur>=0){
            if(arr[cur]==0){
                arr[dest--]=0;
                arr[dest--]=0;
            }else{
                arr[dest--]=arr[cur];
            }
            cur--;
        }
    }
    public void moveZeroes(int[] nums) {
        int l=0,r=0;
        while(r<nums.length){
            if(nums[r]!=0){
                int temp=nums[l];
                nums[l]=nums[r];
                nums[r]=temp;
                l++;
            }
            r++;
        }
    }
}
